package com.yvan.demo;

import com.yvan.PageDb;
import com.yvan.platform.Conv;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class JqwidgetPageDb implements HandlerMethodArgumentResolver {
    public JqwidgetPageDb() {
    }

    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterType() == PageDb.class;
    }

    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        Object arg = webRequest.getParameter("pagenum");
        if (arg == null) {
            return new PageDb(false);
        } else {
            int page = Conv.NI(arg, 0) + 1;
            int limit = Conv.NI(webRequest.getParameter("pagesize"), 10);
            return new PageDb(page, limit, "", false);
        }
    }
}
